var Mozkit = {
  
    json : Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON),
    
    http : {
      
      dataTypes : {
        json : function (request) {
          return Mozkit.json.decode(request.responseText);
        },
        xml : function (request) {
          return request.responseXML;
        },
        text : function (request) {
          return request.responseText;
        }
      },
      
      send : function ( options ) {
        var request = new XMLHttpRequest();
        var requestBody =  Mozkit.object.serialize(options.requestBody);
        
        options.dataType = options.dataType || "text";

        if (options.method.toUpperCase() == "GET") {
          options.url += "?" + requestBody;
          requestBody = null;
        }
  
        request.onreadystatechange = function () {
            if (this.readyState == 4 && this.status == 200) {
              options.callBack(Mozkit.http.dataTypes[options.dataType](this));
            } else if (this.status > 400) {
                options.error(e);
            }
        };
    
        request.open(options.method, options.url, true);
        request.send(requestBody);
      }
    },
    
    object : {
      
      mask : function (object, mask) {
        var output = {};
        for (var i in object) {
          if (typeof object[i] == "string") {
            for (var ii in mask) {
              output[ii] = !(ii in output) ?
                mask[ii].replace("{{" + i + "}}",object[i], "gi") :
                output[ii].replace("{{" + i + "}}",object[i], "gi");
            }
          }
        }
        return output;
      },
      
      serialize : function (object) {
        var r = "";
        for (var key in object) r += key + "=" + object[key] + "&";
        return r.substring(0, r.length-1);
      }
    },
}